function displayScratch () {
var t=document.getElementById('txt').innerHTML;
t=t.replace(/(&)/g,'&amp;');
t=t.replace(/(<)/g,'&lt;');
t=t.replace(/\n--------/g,'\n');
t=t.replace(/\n(Sprite:.*)/g,'<h2>$1</h2>');
t=t.replace(/\n(Scratch:)/,'\n<br>Scratch:');
t=t.replace(/\n(Notes:)/,'\n<h3>$1</h3><pre>');
t=t.replace(/\n(History:)/,'</pre>\n<h3>$1</h3><pre>');
t=t.replace(/\n(Totals:)/,'</pre>\n<h3>$1</h3>');
t=t.replace(/\n+([^ ])/g,' $1');
t=t.replace(/\n(Project:.*)/,'\n<h1>$1</h1>');
t=t.replace(/\n *(Costumes|Sounds) (\([0-9]+\)):/g,'\n<h3>$1 $2</h3>');
t=t.replace(/\n *No stacks\./g,'\n<h3>No scripts</h3>');
t=t.replace(/\n *Stacks (\([0-9]+\)):/g,'\n<h3>Scripts $1</h3>');
t=t.replace(/\n( *)((when I receive|when.*clicked|when.* key pressed).*)/g,'\n<pre class="script">$1<span class="top">$2</span>');
t=t.replace(/\n( *)((play|set instrument|set tempo|set volume|rest|change tempo|change volume|stop all sounds).*)/g,'\n$1<span class="sound">$2</span>');
t=t.replace(/\n( *)((glide|go to |turn |change y by|change x by|point|move |set [xy] |if on edge, bounce|motor).*)/g,'\n$1<span class="motion">$2</span>');
t=t.replace(/\n( *)((change.*effect|change size|go back.*layers|clear graphic|set size|next costume|say |think ).*)/g,'\n$1<span class="looks">$2</span>');
t=t.replace(/\n( *)((clear|pen|set pen|change pen|stamp).*)/g,'\n$1<span class="pen">$2</span>');
t=t.replace(/\n( *)((set |change |show variable |hide variable |add |delete.*of |insert |replace.*of )\".*)/g,'\n$1<span class="variables">$2</span>');
t=t.replace(/\n( *)((show|hide|switch to).*)/g,'\n$1<span class="looks">$2</span>');
t=t.replace(/\n( *)((else|broadcast|repeat|wait|stop|forever|if).*)/g,'\n$1<span class="control">$2</span>');
t=t.replace(/\n( *)((end) *)/g,'\n$1<span class="control">$2</span></pre>');
var stl = document.createElement("style");  
stl.innerHTML="pre.script{line-height:2em;}pre.script span{border-style:solid;border-width:thick;padding-left:1em;padding-right:1em;}.top{border-color:yellow;border-top-left-radius: 50px 100px;border-top-right-radius: 50px 100px;}.control{border-color:yellow;}.sound{border-color:fuchsia;}.looks{border-color:purple;}.motion{border-color:blue;}.variables{border-color:orange;}.pen{border-color:green;}h2{page-break-before:always}br{margin-top:.5em}";
document.getElementsByTagName("head")[0].appendChild(stl);
document.getElementsByTagName("body")[0].innerHTML=t;
var ttl = document.createElement("title");
ttl.innerHTML= document.getElementsByTagName("h1")[0].innerHTML;
document.getElementsByTagName("head")[0].appendChild(ttl);
}

if( window.addEventListener) {
  window.addEventListener('load', displayScratch, false);
} else if (   window.attachEvent) {
   window.attachEvent("onload", displayScratch);
}
